package app.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JTree;
import libs.Attendance;
import libs.Seminar;
import libs.Student;

/**
 *  Akce odstraneni registrace studenta v seminari predmetu
 * @author Dejvino
 */
public class UnregisterStudentAction extends AbstractAction{

    private Attendance attendance;
    private JTree tree = null;

    public UnregisterStudentAction(Attendance attendance){
        if(attendance == null)
            throw new NullPointerException("attendance");
        this.attendance = attendance;
    }

    public void setTree(JTree tree){
        if(tree == null)
            throw new NullPointerException("tree");
        this.tree = tree;
    }

    public void actionPerformed(ActionEvent arg0) {
        if(tree == null)
            throw new NullPointerException("tree is still null!");
        Seminar seminar = (Seminar)tree.getSelectionPath().getPathComponent(2);
        Student student = (Student)tree.getSelectionPath().getPathComponent(3);
        attendance.removeStudent(student, seminar);

        tree.getModel().valueForPathChanged(tree.getSelectionPath().getParentPath(), null);
    }

}
